#include"ringQueue.hpp"
#include<iostream>
#include<unistd.h>
#include<ctime>
using std::cout;
void* consumer(void* argc)
{
    ringQueue<int>* ringQp=static_cast<ringQueue<int>*>(argc);
    while(true)
    {
        sleep(3);
        int data=ringQp->pop();
        cout<<"consumer_pthread["<<pthread_self()<<"]"<<"consumed  a data:"<<data<<endl;
    }
}

void* productor(void* argc)
{
    ringQueue<int>* ringQp=static_cast<ringQueue<int>*>(argc);
    while(true)
    {
        int data=rand()%20;
        ringQp->push(data);
        cout<<"Produtor_pthread["<<pthread_self()<<"]"<<"producted a data"<<data<<endl;
        sleep(1);
    }
}

int main()
{
    srand((unsigned long)time(nullptr)^getpid());
    ringQueue<int> ringQp;
    pthread_t con,pro;
    pthread_create(&con,nullptr,consumer,&ringQp);
    pthread_create(&pro,nullptr,productor,&ringQp);

    pthread_join(con,nullptr);
    pthread_join(pro,nullptr);

    return 0;

}
